//
// speye.cpp
//
// Code generation for function 'speye'
//

// Include files
#include "speye.h"
#include "detrendIBI_priors_data.h"
#include "eml_int_forloop_overflow_check.h"
#include "rt_nonfinite.h"
#include "sparse1.h"
#include "coder_array.h"
#include "mwmathutil.h"

// Variable Definitions
static emlrtRSInfo bc_emlrtRSI{
    17,      // lineNo
    "speye", // fcnName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\eml\\lib\\matlab\\sparfun\\speye.m" // pathName
};

static emlrtRSInfo cc_emlrtRSI{
    33,      // lineNo
    "speye", // fcnName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\eml\\lib\\matlab\\sparfun\\speye.m" // pathName
};

static emlrtRSInfo dc_emlrtRSI{
    21,                           // lineNo
    "checkAndSaturateExpandSize", // fcnName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\eml\\eml\\+coder\\+"
    "internal\\checkAndSaturateExpandSize.m" // pathName
};

static emlrtRSInfo ec_emlrtRSI{
    8,                // lineNo
    "sparse/eyeLike", // fcnName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\shared\\coder\\coder\\+coder\\+internal\\@"
    "sparse\\eyeLike.m" // pathName
};

static emlrtRSInfo fc_emlrtRSI{
    14,               // lineNo
    "sparse/eyeLike", // fcnName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\shared\\coder\\coder\\+coder\\+internal\\@"
    "sparse\\eyeLike.m" // pathName
};

static emlrtRSInfo gc_emlrtRSI{
    20,               // lineNo
    "sparse/eyeLike", // fcnName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\shared\\coder\\coder\\+coder\\+internal\\@"
    "sparse\\eyeLike.m" // pathName
};

static emlrtRSInfo hc_emlrtRSI{
    23,               // lineNo
    "sparse/eyeLike", // fcnName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\shared\\coder\\coder\\+coder\\+internal\\@"
    "sparse\\eyeLike.m" // pathName
};

// Function Definitions
namespace coder {
void speye(const emlrtStack *sp, real_T m, sparse *y)
{
  emlrtStack b_st;
  emlrtStack c_st;
  emlrtStack st;
  int32_T ndiag_tmp_tmp;
  int32_T nzmax;
  st.prev = sp;
  st.tls = sp->tls;
  st.site = &bc_emlrtRSI;
  b_st.prev = &st;
  b_st.tls = st.tls;
  c_st.prev = &b_st;
  c_st.tls = b_st.tls;
  b_st.site = &dc_emlrtRSI;
  if ((m != m) || muDoubleScalarIsInf(m)) {
    emlrtErrorWithMessageIdR2018a(
        &b_st, &j_emlrtRTEI, "Coder:MATLAB:NonIntegerInput",
        "Coder:MATLAB:NonIntegerInput", 4, 12, MIN_int32_T, 12, MAX_int32_T);
  }
  ndiag_tmp_tmp = static_cast<int32_T>(m);
  st.site = &cc_emlrtRSI;
  b_st.site = &ec_emlrtRSI;
  nzmax = static_cast<int32_T>(m);
  y->m = static_cast<int32_T>(m);
  y->n = static_cast<int32_T>(m);
  if (static_cast<int32_T>(m) < 1) {
    nzmax = 1;
  }
  y->maxnz = nzmax;
  y->d.set_size(&fc_emlrtRTEI, &b_st, nzmax);
  y->rowidx.set_size(&gc_emlrtRTEI, &b_st, nzmax);
  if (static_cast<int32_T>(m) + 1 < 0) {
    emlrtNonNegativeCheckR2012b(
        static_cast<real_T>(static_cast<int32_T>(m) + 1), &b_emlrtDCI, &b_st);
  }
  y->colidx.set_size(&hc_emlrtRTEI, &b_st, static_cast<int32_T>(m) + 1);
  b_st.site = &fc_emlrtRSI;
  if (static_cast<int32_T>(m) > 2147483646) {
    c_st.site = &y_emlrtRSI;
    check_forloop_overflow_error(&c_st);
  }
  for (nzmax = 0; nzmax < ndiag_tmp_tmp; nzmax++) {
    y->d[nzmax] = 1.0;
    y->rowidx[nzmax] = nzmax + 1;
  }
  y->colidx[0] = 1;
  b_st.site = &gc_emlrtRSI;
  if (static_cast<int32_T>(m) > 2147483646) {
    c_st.site = &y_emlrtRSI;
    check_forloop_overflow_error(&c_st);
  }
  for (int32_T c{2}; c <= ndiag_tmp_tmp; c++) {
    y->colidx[c - 1] = c;
  }
  nzmax = static_cast<int32_T>(m) + 1;
  ndiag_tmp_tmp = static_cast<int32_T>(m) + 1;
  b_st.site = &hc_emlrtRSI;
  if (static_cast<int32_T>(m) + 1 > 2147483646) {
    c_st.site = &y_emlrtRSI;
    check_forloop_overflow_error(&c_st);
  }
  for (int32_T c{nzmax}; c <= ndiag_tmp_tmp; c++) {
    y->colidx[c - 1] = static_cast<int32_T>(m) + 1;
  }
}

} // namespace coder

// End of code generation (speye.cpp)
